<?php
/**
 * Created by PhpStorm.
 * User: NeverGiveUp
 * Date: 2017/10/25
 * Time: 9:38
 */

namespace Home\Controller;

use Think\Controller;
use Think\Model;

class GoogleController extends Controller
{
    public function Title(){
        header('Content-type:text/html;charset=utf-8');
        echo "我是新的页面";
    }
    public function sql3(){
        header('Content-type:text/html;charset=utf-8');
        $article = M('Myuser');
        //$s = "id>5";
//        $s['name']='王亚';
//        $s['age']=25;
//        $s['_logic']='or';      //表示select语句中的or
        // $s['name|home_city'] = array('like','%安%');  //查询名字或者城市中 带安的
        //$s['id&age'] = array('GT',5);
        $s['_string'] = "age>24 and home_city='六安'";
        $data = $article->where($s)->select();
        var_dump($data);


    }
    Public function sql2(){
        header('Content-type:text/html;charset=utf-8');
        $article = M('Myuser');
        $data = $article->getByName('王亚');
        //根据name为王亚来查询
        $data1 = $article->getFieldByName('王亚','home_city');
        //以name值查询 第一个参数为name的值 第二个参数为要查询的结果
        $data2 = $article->getFieldByGroup_name('1','age');
        //结果只会是一个一维数组只有一个值
        var_dump($data);
        var_dump($data1);
        var_dump($data2);
    }
    public function sql(){
        header('Content-type:text/html;charset=utf-8');
        $myuser = new Model();
        $data = $myuser->query("select * from myuser where id = 4 ");
        //使用query查询的话 就不需要M或者D函数  直接在query里面写select语句就行
        var_dump($data);
        $data2 = $myuser->execute("update myuser set name = '哈撒给' where id = 1");
        //execute 用作更新
        var_dump($data2);
        $data3 = $myuser->execute("delete from myuser where id = 9");
        //execute 用作删除
        var_dump($data3);
        $data4 = $myuser->execute("insert into myuser ('name','group_name','age')VALUES ('周杰伦',2,35)");
        var_dump($data4);

    }

}